using System;
using System.Text;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Xml;
using UnityEngine;
using UnityEditor;
using LS.Localization;

namespace LS.Editor
{
    public class LocalizationSettingMenu
    {
        [MenuItem("Assets/Create/Lancer Studio/Localization/LocalizationSetting",isValidateFunction:true)]
        public static bool CanCreateLocalizationSetting()
        {
            string[] ids = AssetDatabase.FindAssets("t:LS.Localization.LocalizationSetting");
            return ids.Length == 0;
        }

        [MenuItem("Assets/Create/Lancer Studio/Localization/LocalizationSetting")]
        public static void CreateLocalizationSetting()
        {
            string path = LocalizationSettingUtil.GetSelectedFolderPath();
            var setting = LocalizationSettingUtil.CreateOrGetLocalizationSetting($"{path}/LocalizationSetting.asset");
        }

        [MenuItem("Assets/Create/Lancer Studio/Localization/Dictionary XML")]
        public static void CreateDircionaryFile()
        {
            LocalizationSettingUtil.CreateDirectory();
        }
        
        [MenuItem("Assets/Create/Lancer Studio/Localization/Dictionary CSV")]
        public static void CreateDircionaryCSVFile()
        {
            string[] keys = new string[] { "Key", String.Empty, "Value" };
            string[] types = new string[] { "string", String.Empty, "string" };
            string[] notes = new string[] { "键", "备注", "值" };
            CreateCSV("Dictionary.csv" , keys, types, notes);
        }

        public static void TurnXMLToCSV()
        {
            string path = "Assets/LSRuntime/Assets/Localization/ChineseSimplified/Dictionary.xml";
            string target = "Assets/LSRuntime/Assets/Localization/ChineseSimplified/Dictionary.csv";
            string[] keys = new string[] { "Key", String.Empty, "Value" };
            string[] types = new string[] { "string", String.Empty, "string" };
            string[] notes = new string[] { "键", "备注", "值" };
            string titleText = CSVUtility.CombinBaseText("Dictionary",CSVUtility.Table, keys, types, notes);
            XmlDocument xmld = new XmlDocument();
            xmld.Load(path);
            XmlElement panel = xmld.GetDictionaryPanel();
            XmlElement content = panel.FirstLanguageContent();
            while (content != null)
            {
                
            }
        }
        public static void CreateCSV(string fileName, string[] keys, string[] types, string[] notes)
        {
            string name = Path.GetFileNameWithoutExtension(fileName);
            ProjectWindowUtil.CreateAssetWithContent(fileName, CSVUtility.CombinBaseText(name, CSVUtility.Table, keys, types, notes));
        }
    }
}
